package com.ykt.model;

import com.jfinal.plugin.activerecord.Page;

import java.util.Map;

/**
 * 支付记录
 * @author wing
 * @version 1.0.0
 */
public class PayRecord extends BaseModel<PayRecord> {
    private static final long serialVersionUID = 1L;

    public static final String pay_no = "pay_no";
    public static final String order_id = "order_id";
    public static final String serial_no = "serial_no";
    public static final String account = "account";
    public static final String pay_time = "pay_time";
    public static final String user_id = "user_id";
    public static final String status = "status";

    public static final PayRecord dao = new PayRecord();

    @Override
    public Page<PayRecord> pageFindModel(int pageNumber, int rows, Map<String, String> paramMap) {
        String select = "SELECT pr.id, pr.pay_no payNo, pr.serial_no serialNo, pr.account, pr.status,pr.order_id orderId, pr.pay_time payTime, "
        		+ " u.name userName,u.phone userPhone, s.name shopName, "
        		+ " o.created_time createTime,o.order_no, o.amount,o.community_name,o.receipt_name,o.receipt_phone,o.agent_fee ";
        String sqlExceptSelect = " FROM pay_record pr "
        		+ " left join `order` o on pr.order_id=o.id "
        		+ " left join `user` u on o.user_id = u.id "
        		+ " left join `shop` s on o.shop_id=s.id ";
        String sqlOrderBy = " ORDER BY pr.id DESC ";
        
        paramMap.put(OB, sqlOrderBy);
        
        return this.pageFindModel(select, sqlExceptSelect, pageNumber, rows, paramMap);
    }
    
    public PayRecord getViewById(Long id) {

    	PayRecord model_;
        try {
        	String sql = "SELECT pr.id,pr.pay_no payNo, pr.serial_no serialNo, pr.account, pr.status, pr.order_id orderId, pr.pay_time payTime, "
            		+ " u.name userName,u.phone userPhone, s.name shopName, "
            		+ " o.created_time,o.order_no, o.amount,o.receipt_name, o.receipt_phone,o.address,o.community_name,o.status orderStatus "
            		+ " FROM pay_record pr "
            		+ " left join `order` o on pr.order_id=o.id "
            		+ " left join `user` u on o.user_id = u.id "
            		+ " left join `shop` s on o.shop_id=s.id "
        			+ " where pr.id=? ";
        	model_ = this.findFirst(sql, id);
        	
            return model_;
        } catch (Exception e) {
        }
        return null;
    }

}
